package com.daogu.fuelcard.utils;

import org.springframework.http.HttpStatus;

public class Result<T> {

    private T data;

    private String msg;

    private Integer code;

    private Boolean success;

    public static <T> Result<T> accept(T data) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatus.OK.value());
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> accept() {
        Result<T> result = new Result<>();
        result.setCode(HttpStatus.OK.value());
        result.setSuccess(true);
        return result;
    }

    public  static <T> Result<T> error(String msg) {
        Result<T> result = new Result<T>();
        result.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        result.setSuccess(false);
        result.setMsg(msg);
        return result;
    }

    public Result() {}

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }
}
